package com.ocom.mjrecode.controller;

import com.ocom.common.constant.MjRecodeUrl;
import com.ocom.common.entity.mjrecode.MjRecord;
import com.ocom.common.request.srvpaccess.GetNosendRecordRequest;
import com.ocom.common.request.srvpaccess.SendAccessRecordRequest;
import com.ocom.common.request.srvpaccess.UpdateAvatarRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.mjrecode.service.MjRecodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2023/4/7
 **/
@RestController
public class MjRecodeController {


	@Autowired
	MjRecodeService mjRecodeService;

	@PostMapping(MjRecodeUrl.URL_getAccessRecNum)
	public Result  getAccessRecNum(Long beginComId, Long endComId ,String month){
		return ResultUtil.success(mjRecodeService.getMjCountByComId(beginComId,endComId,month));
	}

	@PostMapping(MjRecodeUrl.URL_getSubDbAccessRecNum)
	public Result  getSubDbAccessRecNum(Long beginComId, Long endComId ,String month){
		Map<String,Object>  resmap = new HashMap<>();
		resmap.put("mjRecNum",mjRecodeService.getMjCount(beginComId,endComId,month));
		return ResultUtil.success(resmap);
	}


	@PostMapping(MjRecodeUrl.URL_getAccessMonthData)
	public Result  getAccessMonthData(Long comId,String beginMonth, String endMonth ){
		return mjRecodeService.getMjCount(comId,beginMonth,endMonth);
	}


	@PostMapping(MjRecodeUrl.URL_getSubDbAccessMonthData)
	public Result  getSubDbAccessMonthData(Long beginComId, Long endComId ,String beginMonth, String endMonth ){
		return mjRecodeService.getMjCount(beginComId,endComId,beginMonth,endMonth);
	}

	@PostMapping(value = MjRecodeUrl.URLP_getNosendRecord)
	public Result getNosendRecord(@RequestBody GetNosendRecordRequest request){
		List<MjRecord> list = mjRecodeService.getNosendRecord(request.getComId(),request.getBeginTime(),request.getTarget(), request.getSize(), request.getYearDate());
		return ResultUtil.success(list);
	}

	@PostMapping(value = MjRecodeUrl.URLP_sendAccessRecord)
	public Result sendAccessRecord(@RequestBody SendAccessRecordRequest request){
		return ResultUtil.success(mjRecodeService.sendAccessRecord(request.getComId(),request.getId(), request.getTarget(), request.getMonthValue()));
	}


	@PostMapping(value = MjRecodeUrl.URLP_updateAvatar)
	public Result updateAvatar(@RequestBody UpdateAvatarRequest request){
		return ResultUtil.success(mjRecodeService.updateAvatar(request));
	}




}
